// models/attachmentModel.js
const pool = require('../config/db');

const getAttachmentsByBlogId = async (blog_id) => {
  const [rows] = await pool.query('SELECT * FROM attachments WHERE blog_id = ?', [blog_id]);
  return rows;
};

const createAttachment = async (blog_id, file_name, file_path) => {
  const [result] = await pool.query('INSERT INTO attachments (blog_id, file_name, file_path) VALUES (?, ?, ?)', [blog_id, file_name, file_path]);
  return result.insertId;
};

const deleteAttachment = async (id) => {
  await pool.query('DELETE FROM attachments WHERE attachment_id = ?', [id]);
};

module.exports = {
  getAttachmentsByBlogId,
  createAttachment,
  deleteAttachment,
};
